package com.mj.user.api.impl;

import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.mj.user.dao.UserDao;
import com.mj.user.entity.User;
import com.mj.user.service.UserService;
import com.mj.util.IDUtils;


/**
 * 约定生产者在实现类上提供dubbo服务
 * 消费者在xml中配置
 * ps:都可以在xml中配置
 * @author majie
 *
 */
@Service("userService")
public class UserServiceImpl implements UserService {

	@Autowired
	private UserDao dao;
	
	public User getByColumn(String userName) {
		Map<String, Object> map = new HashMap<>();
		map.put("userName", userName);
		return this.dao.getByColumn(map);
	}

	public List<User> getList() throws Exception {
		List<User> list = this.dao.listBy(null);
		if(!list.isEmpty()){
			return list;
		} else {
			return Collections.emptyList();
		}
	}

	public void insert(User user) throws Exception {
		user.setCreateTime(new Date());
		user.setId(IDUtils.getID());
		dao.insert(user);
	}

	public void update(User user) throws Exception {
		dao.update(user);
	}



}
